package com._520it.crm.web.controller;

import com._520it.crm.domain.ClassInfo;
import com._520it.crm.page.AjaxResult;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.ClassInfoQueryObject;
import com._520it.crm.service.IClassInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/classinfo")
public class ClassInfoController {
	@Autowired
	private IClassInfoService classinfoService;
	//@RequiresPermissions("classinfo:index")
	//@PermissionName("班级列表")
	@RequestMapping("")
	public String index(){
		return "classinfo";
	}
	//@RequiresPermissions("classinfo:list")
	//@PermissionName("班级数据")
	@RequestMapping("/list")
	@ResponseBody
	public PageResult list(ClassInfoQueryObject qo){
		PageResult result = classinfoService.queryPage(qo);
		return result;
	}
	//@RequiresPermissions("classinfo:save")
	//@PermissionName("班级新增")
	@RequestMapping("/save")
	@ResponseBody
	public AjaxResult save(ClassInfo classinfo){
		AjaxResult result = null;
		try{
			classinfoService.insert(classinfo);
			result = new AjaxResult(true,"保存成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("保存失败,请联系管理员!");
		}
		return result;
	}
	//@RequiresPermissions("classinfo:update")
	//@PermissionName("班级更新")
	@RequestMapping("/update")
	@ResponseBody
	public AjaxResult update(ClassInfo classinfo){
		AjaxResult result = null;
		try{
			classinfoService.updateByPrimaryKey(classinfo);
			result = new AjaxResult(true,"更新成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("更新失败,请联系管理员!");
		}
		return result;
	}
	//@RequiresPermissions("classinfo:quit")
	//@PermissionName("班级删除")
	@RequestMapping("/delete")
	@ResponseBody
	public AjaxResult delete(Long id){
		AjaxResult result = null;
		try{
			classinfoService.deleteByPrimaryKey(id);
			result = new AjaxResult(true,"删除成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("删除失败,请联系管理员!");
		}
		return result;
	}
}
